import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, Index } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";
import { CharacterMountEntity } from "./character-mount.entity";

@Entity("mount_training")
@ManualTimestamp()
export class MountTrainingEntity {
  @PrimaryGeneratedColumn({ comment: "训练记录ID" })
  id!: number;

  @Column("int", { name: "characterId", comment: "角色ID" })
  characterId!: number;

  @Column("int", { comment: "玩家坐骑ID" })
  characterMountId!: number;

  @Column("date", { comment: "训练日期" })
  trainingDate!: Date;

  @Column("int", { default: 0, comment: "当日训练次数" })
  dailyCount!: number;

  @Column("int", { default: 0, comment: "累计获得经验" })
  totalExperience!: number;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;
@Column("datetime", { name: "updated_at", nullable: true, comment: "更新时间" })
  updated_at!: Date | null;
// 关联关系
  @ManyToOne(() => CharacterEntity)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;

  @ManyToOne(() => CharacterMountEntity)
  @JoinColumn({ name: "characterMountId" })
  characterMount!: CharacterMountEntity;

  // 复合索引：角色ID + 坐骑ID + 日期，确保每天每匹坐骑只有一条记录
  // 注意：这个索引在数据库层面创建，不需要在实体中定义字段
}
